package sicau.car.utill;

import org.springframework.scheduling.annotation.Scheduled;

import java.util.HashMap;

/**
 * @Author ITcz
 * @Data 2020-09-28 - 16:22
 */

public class TokenUtil {
    private static HashMap<String,Integer> tokenMap = new HashMap();

    public static String setToken(Integer adminCampus){
        //生成一段随机值并赋值给token
        String token = UUIDUtil.uuid();
        //将token和管理员的校区码放入map里
        tokenMap.put(token, adminCampus);
        return token;
    }

    public static Integer getCampusByToken(String token){
        return (Integer) tokenMap.get(token);
    }

    public static boolean containsToken(String token) {
        return tokenMap.containsKey(token);
    }

    public static void removeToken(String token){
        tokenMap.remove(token);
    }

    public static void showAll(){
        for (String key:
        tokenMap.keySet()
             ) {
            System.out.println(key +":"+ tokenMap.get(key));
        }
    }

    public static void deleteAll(){
        System.out.println("clean all token msg");
        tokenMap.clear();
    }
}
